﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HAZ.WinDBConnection.Forms
{
    public partial class Logon : Form
    {
        public Logon()
        {
            InitializeComponent();

            this.Text = ConnectionFactory.DBConnection.Default.Alias + " " + this.Text;

            if (Session.DataAtual < ConnectionFactory.DBConnection.Default.LastRUN)
            {
                MessageBox.Show(String.Format("Data do sistema({0}) é inferior a ultima execução({1})."
                    , Session.DataAtual.ToString("dd/MM/yyyy")
                    , ConnectionFactory.DBConnection.Default.LastRUN.ToString("dd/MM/yyyy"))
                    , this.Text);

                Environment.Exit(0);
            }
        }

        private void btnLogar_Click(object sender, EventArgs e)
        {
            Session.Password = txtLogin.Text;
            ConnectionFactory.DBConnection.Default.LastRUN = DateTime.Today;
            this.Close();
        }

        private void txtLogin_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnLogar_Click(sender, e);
            }
        }

        private void Logon_Load(object sender, EventArgs e)
        {
            lblStartMsg.Text = ConnectionFactory.DBConnection.Default.StartMsg;
        }
    }
}
